package com.xnsy.jishexiangmu.mapper;

import com.xnsy.jishexiangmu.pojo.JuBao;
import com.xnsy.jishexiangmu.pojo.RenZheng;
import com.xnsy.jishexiangmu.pojo.User;
import com.xnsy.jishexiangmu.pojo.UserMessage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user where username=#{username}")
    User findByUsername(String username);
    @Insert("insert into user(username,password,register_time,update_time, authentication)" +
    "values (#{username},#{password},now(),now(), '普通用户')"
    )
    void register(String username, String password);
    @Insert("insert into usermessage(username)" +
            "values(#{username})")
    void createUserMessage(String username);
    @Update("update user set password=#{newPassword} where username=#{username}")
    void updatePassword(String newPassword,String username);
    @Select("select * from usermessage where username=#{username}")
    UserMessage getUserMessage(String username);
    @Update("update usermessage set name=#{name},age=#{age},gender=#{gender},phone=#{phone},email=#{email},authentication=#{authentication} where username=#{username}")
    void updateUserMessage(UserMessage userMessage);
    @Insert("insert into renzheng(username,authentication,create_time,to_where)" +
            "values (#{username},#{renzheng},now(),#{toWhere})")
    void renzheng(String renzheng, String username, String toWhere);
    @Select("select * from renzheng")
    List<RenZheng> getrenzheng();
    @Update("update renzheng set isaccept = #{isaccept},isneed = 0 where username = #{username}")
    void setRenZheng(String username, Integer isaccept);
    @Update("update user set authentication = #{authentication},to_where=#{toWhere} where username = #{username}")
    void setAuthentication(String username, String authentication, String toWhere);
    @Select("select * from user where authentication = #{s}")
    List<User> getAllUser(String s);
    @Update("update user set isroot = #{isroot} where uid = #{uid}")
    void setRoot(Integer isroot, Integer uid);
    @Insert("insert into jubao(name,sex,email,phone,diqu,contain,username,jindu,create_time) " +
            "values (#{name},#{sex},#{email}, #{phone},#{diqu},#{contain},#{username},2,now()) ")
    void postMessage(JuBao juBao);
    @Select("select jindu from jubao where username = #{username}")
    int getJinDu(String username);
    @Select("select  * from jubao")
    List<JuBao> getJuBao();
    @Update("update jubao set jindu = 3 where id = #{id}")
    void setJinDu(Integer id);
}
